<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								渠道名称：<input type="text" name="name"/>
							</li>

							<li>
								渠道编码：<input type="text" name="code"/>
							</li>

							<li>
								方法类名：<input type="text" name="className"/>
							</li>

							<li>
								接口地址: <input type="text" name="reqUrl"/>
							</li>

							<!--<li>
								代付优先级：<input type="text" name="withdrawalLevel"/>
							</li>-->

							<li>
								状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-primary" onclick="$.operate.add()" shiro:hasPermission="channel:channelInfo:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="channel:channelInfo:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap !important;"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('channel:channelInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('channel:channelInfo:remove')}]];
        var iplist = [[${@permission.hasPermi('channel:channelInfo:iplist')}]];
        var prefix = ctx + "channel/channelInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "渠道信息",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id',
					title : '渠道标识',
					visible: false
				},
					{
					field : 'name',
					title : '渠道名称',
					sortable: true
				},
				{
					field : 'code',
					title : '渠道编码',
					sortable: true
				},
				{
					field : 'secretKey',
					align: 'center',
					title : '渠道秘钥',
					formatter: function (value,row,index){
						return $.table.tooltip(value,25);
					}
				},
				{
					field : 'className',
					align: 'center',
					title : '方法类名'
				},
				{
					field : 'reqUrl',
					align: 'center',
					title : '接口地址',
					formatter: function (value,row,index){
						return $.table.tooltip(value,25);
					}
				},
					{
                    field : 'withdrawalLevel',
                    title : '代付优先级',
                    align: 'center',
                    sortable: true
                },
					{
					field : 'withdrawalFee',
					title : '代付手续费(元)',
                    align: 'center',
					sortable: true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
					{
					field : 'mchWithdrawalFee',
					title : '商户代付手续费(元)',
					align: 'center',
					sortable: true,
					formatter: function (value, row, index) {
						if (value != null) {
							var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
							return data;
						}
					}
                },
                {
                    field : 'withdrawalInner',
                    title : '代付内扣',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return "是"
						}
						if (value === 1) {
						    return "否"
						}
                    }
                },
				{
					field : 'withdrawalLimtLeft',
					title : '代付限额(元)',
					align: 'center',
					sortable: true,
					formatter: function (value, row, index) {
						if (value != null && row.withdrawalLimtRight != null) {
							var withdrawalLimtLeft = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                	        var withdrawalLimtRight = new Decimal(row.withdrawalLimtRight).div(new Decimal(100.00)).toFixed(2);
							return withdrawalLimtLeft + "~" + withdrawalLimtRight;
						}
					}
                },
				{
					field : 'contactName',
					title : '联系人姓名',
					visible: false,
					sortable: true
				},
				{
					field : 'contactPhone',
					title : '联系人手机',
					visible: false,
					sortable: true
				},
				{
					field : 'contactEmail',
					title : '联系人电话',
					visible: false,
					sortable: true
				},
				{
                    visible: editFlag == 'hidden' ? false : true,
                    field : 'status',
                    title : '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return mpChannel_statusTools(row);
                    }
                },
				{
		         title: '操作',
		         align: 'center',
		         formatter: function(value, row, index) {
		         	var actions = [];
                     actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="payMethod(\'' + row.id + '\')"><i class="fa fa-edit"></i>支付方法</a> ');
                     actions.push('<a class="btn btn-info btn-xs ' + iplist + '" href="#" onclick="channelIP(\'' + row.id + '\')"><i class="fa fa-edit"></i>IP白名单</a> ');
                     /*actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="withdrawalBank(\'' + row.id + '\')"><i class="fa fa-edit"></i>代付银行</a> ');*/
                     actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                     actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
					return actions.join('');
		         	}
		        }]
            };
            $.table.init(options);
        });

        /**
         *渠道状态显示
         */
        function mpChannel_statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="mpChannel_enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="mpChannel_disable(\'' + row.id + '\')"></i> ';
            }
        }

        /**
         * 渠道状态-停用
         */
        function mpChannel_disable(mpChannelId) {
            $.modal.confirm("确认要停用所选渠道吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"id": mpChannelId, "status": 1})
            });
        }

        /**
         * 渠道状态-启动
         */
        function mpChannel_enable(mpChannelId) {
            $.modal.confirm("确认要启用所选渠道吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"id": mpChannelId, "status": 0})
            });
        }



        /**
         *内扣状态显示
         */
        function mpChannel_innerStatusTools(row) {
            if (row.withdrawalInner == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="mpChannel_inner_enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="mpChannel_inner_disable(\'' + row.id + '\')"></i> ';
            }
        }

        /**
         * 内扣状态-停用
         */
        function mpChannel_inner_disable(mpChannelId) {
            $.modal.confirm("确认要停用内扣吗？", function () {
                $.operate.post(prefix + "/changeInnerStatus", {"id": mpChannelId, "withdrawalInner": 1})
            });
        }

        /**
         * 内扣状态-启动
         */
        function mpChannel_inner_enable(mpChannelId) {
            $.modal.confirm("确认要启用内扣吗？", function () {
                $.operate.post(prefix + "/changeInnerStatus", {"id": mpChannelId, "withdrawalInner": 0})
            });
        }






        /* 代付银行*/
        function withdrawalBank(mpChannelId) {
            var url = prefix + '/withdrawalBank/' + mpChannelId;
            $.modal.openTab("渠道-代付银行", url);
        }


        /*渠道支付方法*/
        function payMethod(mpChannelId) {
            var url = prefix + '/payMethod/' + mpChannelId;
            $.modal.openTab("渠道-支付方法", url);
        }


        /*渠道-IP黑白名单*/
		function channelIP(mpChannelId) {
            var url = prefix + '/ipList/' + mpChannelId;
            $.modal.openTab("渠道-IP白名单", url);
        }
	</script>
</body>
</html>